from logic import Circuit, Connection, IOCircuit,OrGate,AndGate,Multioutput

def listSum(lists):
    ret = []
    for lst in lists:
        ret += lst
    return ret

def listSumUnzip(lists):
    ret = []
    for id,lst in lists:
        ret.append(lst)
    return ret    
    

def getOrGate(list):    
    for gate in list:
        if(isinstance(gate,OrGate)):
            return gate
    return None

def getNextOrGateConn(gate):    
    for conn in gate.outputList:
        if(isinstance(conn.output,OrGate)):
            return conn
    return None

def getNextGateConn(gate,nextGateClass):    
    for conn in gate.outputList:
        while isinstance(conn.output,Connection):
            conn = conn.output                    
        if(isinstance(conn.output,nextGateClass)):
            return conn
    return None

def isInputA(conn,gate):
    if(gate.inputList[0] == conn):
        return True
    return False

def isInputB(conn,gate):
    if(gate.inputList[1] == conn):
        return True
    return False

def getOtherInput(gate,input):    
    for conn in gate.inputList:
        if(conn != input):
            return conn
    return None
